package finance;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

import java.util.List;

import org.junit.Before;
import org.junit.Test;

public class FFTTest {
    private FFT fft = new FFT();

    public double f(double x) {
        return 7 + Math.sin(2 * Math.PI * x / 23)
                - Math.cos(2 * Math.PI * x / 42)
                + Math.sin(2 * Math.PI * x / 7);
    }
    
    @Test
    public void testShift() {
        assertEquals(2, fft.shift(0, 4));
        assertEquals(3, fft.shift(1, 4));
        assertEquals(0, fft.shift(2, 4));
        assertEquals(1, fft.shift(3, 4));
    }
    
    @Test
    public void testFft() {
        double[] doubles = new double[2048];
        
        for (int i = 0; i < doubles.length; i++) {
            doubles[i] = f(i);
        }
        
        List<Long> periods = fft.fft(doubles);
        
        assertEquals( 23, periods.get(periods.size() - 1).intValue() );
        assertEquals( 42, periods.get(periods.size() - 2).intValue() );
        assertEquals( 7, periods.get(periods.size() - 3 ).intValue());
    }
}
